/**
 * FileName: Grapth
 * Author:   powersi
 * Date:     2021/1/13 8:44
 * Description:
 */
package com.zm.demo.core.leetcode.search;

import java.util.LinkedList;

/**
 * Description: 
 * Author:      powersi
 * Date:        2021/1/13 8:44
 */
public class Graph {

    private int v;
    private LinkedList<Integer>[] adj;

    public Graph(int v) {
        this.v = v;
        adj = new LinkedList[v];
        for (int i = 0; i < v; i++) {
            adj[i] = new LinkedList<>();
        }
    }

    public void addEdge(int s, int t){
        adj[s].add(t);
        adj[t].add(s);
    }

    /**
     *  0 - 1 - 2
     *  |   |   |
     *  3 - 4 - 5
     *  |   |   |
     *  6 - 7 - 8
     *
     */
    public void buildGraph(){
        addEdge(0,1);
        addEdge(0,3);

        addEdge(1,2);
        addEdge(1,4);

        addEdge(2,5);

        addEdge(3,4);
        addEdge(3,6);

        addEdge(4,5);
        addEdge(4,7);

        addEdge(5, 8);

        addEdge(7, 8);
    }

    public int getV() {
        return v;
    }

    public void setV(int v) {
        this.v = v;
    }

    public LinkedList<Integer>[] getAdj() {
        return adj;
    }

    public void setAdj(LinkedList<Integer>[] adj) {
        this.adj = adj;
    }
}
